<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html lang="en">
<base href="<%=basePath%>">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
<%@include file="/esayuiStyle.jsp" %>
<script type="text/javascript">
$(function(){
	$("#prescribeTable").datagrid({
		pagination:true,
		idField:"id"
	});
	$("#dictionaryParent").datagrid({
		idField:"id"
	}) 
	
	$("#dictionaryParent").datagrid({
		onClickRow:function (){
			var id = $("#dictionaryParent").datagrid('getSelected');
			var postData = {'parent.id':id.id};
			$("#dictionaryTable").datagrid("reload",postData);	
		}
		
	})
})
		function bingrenFormatter(value,row,index){
			return row.patient.name;
		}
//添加
function addPre(){
	var d = $("<div></div>").appendTo("body");
	d.dialog({
		title:"添加器械",
		width:500,
		height:300,
		modal:true,
		href:"prescribe/prescribeForm",
		onClose:function(){$(this).dialog("destroy");},
		buttons:[{
			text:"确定",
			handler:function(){
				$("#preForm").form("submit",{
					url:"prescribe/add",
					success:function(data){
						d.dialog("close");
						$("#prescribeTable").datagrid("reload");
					}
				});
			}
		},{
			text:"取消",
			handler:function(){
				d.dialog("close");
			}
		}]
	});
}
//修改
function editPre(){
	var row = $("#prescribeTable").datagrid("getSelected");
	if(row == null){
		return;
	}
	$("#prescribeTable").datagrid("clearSelections");
	$("#prescribeTable").datagrid("selectRecord",row.id);
	var d = $("<div></div>").appendTo("body");
	d.dialog({
		title:"编辑",
		width:500,
		height:300,
		modal:true,
		href:"prescribe/prescribeForm",
		onClose:function(){$(this).dialog("destroy");},
		onLoad:function(){
			$.post("prescribe/view",{id:row.id},function(data){
				$("#preForm").form("load",data);
				
			});
		},
		buttons:[{
			text:"确定",
			handler:function(){
				$("#preForm").form("submit",{
					url:"prescribe/edit",
					success:function(data){
						d.dialog("close");
						$("#prescribeTable").datagrid("reload");
					}
				});
			}
		},{
			text:"取消",
			handler:function(){
				d.dialog("close");
			}
		}]
	});
}
function deletePre(){
	var selRows = $("#prescribeTable").datagrid("getSelections");
	if(selRows.length == 0){
		$.messager.alert("提示","请选中要删除的数据行！","warning");
		return;
	}
	$.messager.confirm("提示","确定要删除选中的数据吗？",function(r){
		if(r){
			//3. 发送异步请求，带选中行的编号
			//拼接删除条件
			var postData = "";
			$.each(selRows,function(i){
				postData += "ids="+this.id;
				if(i < selRows.length - 1){
					postData += "&";
				}
			});
		}
		$.post("prescribe/deletepre",postData,function(data){
			if(data.result == true){
				//4. 删除成功后，刷新表格 reload
				$("#prescribeTable").datagrid("reload");
			}
		});
	});
}
</script>
</head>
<body>
<a href="javascript:void(0)" class="easyui-linkbutton" onclick="addPre();" data-options="iconCls:'icon-add',plain:true">添加</a>
	<a href="javascript:void(0)" class="easyui-linkbutton" onclick="editPre();" data-options="iconCls:'icon-edit',plain:true">修改</a>
	<a href="javascript:void(0)" class="easyui-linkbutton" onclick="deletePre();" data-options="iconCls:'icon-remove',plain:true">删除</a>
	<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-undo',plain:true">导出</a>
	<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-sum',plain:true">批量导入</a>



			<table class="easyui-datagrid" id="prescribeTable" title="prescribe list"
					data-options="url:'prescribe/list',method:'post',fitColumns:true,striped:true,rownumbers:true ">
				<thead>
					<tr>
						<th data-options="field:'id'" width="100">处方编号</th>
						<th data-options="field:'seeDoctorRegisterId'" width="80">就诊登记编号</th>
						<th data-options="field:'sdasd',align:'right',formatter:bingrenFormatter" width="80">病人编号</th>
						<th data-options="field:'days',align:'right'" width="80">天数</th>
						<th data-options="field:'dispensing',align:'right'" width="80">是否发药</th>
						<th data-options="field:'state',align:'center'" width="80
						">状态</th>
					</tr>
				</thead>
			</table>
</body>
</html>